package cn.service.Impl;

import cn.mapper.AdminMapper;
import cn.pojo.Admin;
import cn.pojo.AdminExample;
import cn.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author jia
 * @Description
 * @date 2019-03-20-20:27
 */
@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    AdminMapper adminMapper;

    @Override
    public List<Admin> list() {
        AdminExample example = new AdminExample();
        example.setOrderByClause("id desc");
        return adminMapper.selectByExample(example);
    }

    @Override
    public Admin get(String name, String password) {
        AdminExample example = new AdminExample();
        example.createCriteria().andAdminNameEqualTo(name).andAdminPasswordEqualTo(password);
        List<Admin> admins = adminMapper.selectByExample(example);
        if (admins.isEmpty()) {
            return null;
        }
        return admins.get(0);
    }
}
